package com.example.spring_boot_demo.controller;


import com.example.spring_boot_demo.dto.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotBlank;
import java.util.HashMap;
import java.util.Map;

@Validated
@RestController
@RequestMapping("/form")
public class DemoController {

    @Autowired
    //@Qualifier(value = "testController")

    //
    //@Resource(name="testController")
    private TestController testController;

    private static final Logger log = LoggerFactory.getLogger(DemoController.class);

    @RequestMapping("/getBean")
    @ResponseBody
    public String getBean(){
        log.info("{}",testController);
        return "this is response";
    }
    @RequestMapping("/findOne")
    @ResponseBody
    public String findOne(){
        log.info("{}",1);
        return "this is response";
    }

    /**
     * 参数校验
     * @param user
     */
    @GetMapping("/checkParam")
    public Map checkParam(@Validated User user) throws InterruptedException {
        Thread.sleep(3000);
        Map<Object, Object> hashMap = new HashMap<>();
        hashMap.put("data",user);
        hashMap.put("code",200);
        return hashMap;
    }

    /**
     * 参数校验
     * @param name
     */
    @GetMapping("/findStudentById")
    public User findStudentById(@NotBlank(message = "name 不能为空")  String name){
        User user = new User();
        user.setAge(10);
        user.setName(name);
        user.setName("123");
        return user;
    }
}
